package com.ruoyi.caiwu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.caiwu.domain.AccountingVoucherEntry;
import com.ruoyi.caiwu.service.IAccountingVoucherEntryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证分录Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/entry")
public class AccountingVoucherEntryController extends BaseController
{
    @Autowired
    private IAccountingVoucherEntryService accountingVoucherEntryService;

    /**
     * 查询凭证分录列表
     */
    @RequiresPermissions("caiwu:entry:list")
    @GetMapping("/list")
    public TableDataInfo list(AccountingVoucherEntry accountingVoucherEntry)
    {
        startPage();
        List<AccountingVoucherEntry> list = accountingVoucherEntryService.selectAccountingVoucherEntryList(accountingVoucherEntry);
        return getDataTable(list);
    }

    /**
     * 导出凭证分录列表
     */
    @RequiresPermissions("caiwu:entry:export")
    @Log(title = "凭证分录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountingVoucherEntry accountingVoucherEntry)
    {
        List<AccountingVoucherEntry> list = accountingVoucherEntryService.selectAccountingVoucherEntryList(accountingVoucherEntry);
        ExcelUtil<AccountingVoucherEntry> util = new ExcelUtil<AccountingVoucherEntry>(AccountingVoucherEntry.class);
        util.exportExcel(response, list, "凭证分录数据");
    }

    /**
     * 获取凭证分录详细信息
     */
    @RequiresPermissions("caiwu:entry:query")
    @GetMapping(value = "/{entryId}")
    public AjaxResult getInfo(@PathVariable("entryId") Long entryId)
    {
        return success(accountingVoucherEntryService.selectAccountingVoucherEntryByEntryId(entryId));
    }

    /**
     * 新增凭证分录
     */
    @RequiresPermissions("caiwu:entry:add")
    @Log(title = "凭证分录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountingVoucherEntry accountingVoucherEntry)
    {
        return toAjax(accountingVoucherEntryService.insertAccountingVoucherEntry(accountingVoucherEntry));
    }

    /**
     * 修改凭证分录
     */
    @RequiresPermissions("caiwu:entry:edit")
    @Log(title = "凭证分录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountingVoucherEntry accountingVoucherEntry)
    {
        return toAjax(accountingVoucherEntryService.updateAccountingVoucherEntry(accountingVoucherEntry));
    }

    /**
     * 删除凭证分录
     */
    @RequiresPermissions("caiwu:entry:remove")
    @Log(title = "凭证分录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{entryIds}")
    public AjaxResult remove(@PathVariable Long[] entryIds)
    {
        return toAjax(accountingVoucherEntryService.deleteAccountingVoucherEntryByEntryIds(entryIds));
    }
}
